from flask import Flask, render_template, request, jsonify, Blueprint

import os


demo_dp = Blueprint('demo', __name__, url_prefix='/api')


@demo_dp.route('/aa', methods=['GET'])
def data():
    try:

        return jsonify({
            'message': '添加数据成功',
            'data': 1
        }), 201
       
    except Exception as e:
        print('e', e)
        return jsonify({
            "error": '报错了',
            "message": e
        }), 400



@demo_dp.route('/data', methods=['POST'])
def add_data():
    try:


        new_data = request.get_data()

        if new_data:
            ss = eval( new_data.decode(encoding='utf8') )

            return jsonify({
                'message': '添加数据成功',
                'data': ss
            }), 201
        else :
            return jsonify({
                "error": '数据不对'
            }), 400
    except Exception as e:
        print('e', e)
        return jsonify({
            "error": '报错了',
            "message": e
        }), 400

@demo_dp.route('/login/account', methods=['POST'])
def login():
    try:


        new_data = request.json

        if new_data:
            return jsonify(
                {
                    'status': 'ok',
                    'type': new_data['type'],
                    'currentAuthority': 'admin',
                    'token': '123'
                }
            ), 200
        else :
            return jsonify({
                "error": '数据不对'
            }), 400
    except Exception as e:
        print('e', e)
        return jsonify({
            "error": '报错了',
            "message": e
        }), 400

@demo_dp.route('/currentUser', methods=['GET'])
def currentUser():
    try:

        return jsonify(
            {
                'success': 'true',
                'data': {
                    'name': 'Serati Ma',
                    'avatar':
                        'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
                    'userid': '00000001',
                    'email': 'antdesign@alipay.com',
                    'signature': '海纳百川，有容乃大',
                    'title': '交互专家',
                    'group': '蚂蚁金服－某某某事业群－某某平台部－某某技术部－UED',
                    'tags': [
                        {
                            'key': '0',
                            'label': '很有想法的',
                        },
                        
                    ],
                    'notifyCount': 12,
                    'unreadCount': 11,
                    'country': 'China',
                    'access': 'true',
                    'geographic': {
                        'province': {
                            'label': '浙江省',
                            'key': '330000',
                        },
                        'city': {
                            'label': '杭州市',
                            'key': '330100',
                        },
                    },
                    'address': '西湖区工专路 77 号',
                    'phone': '0752-268888888',
                },
            }
        ), 201

    except Exception as e:
        print('e', e)
        return jsonify({
            "error": '报错了',
            "message": e
        }), 400

